package iuyfgvbcd;

import android.app.Activity;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.example.coco2dxgame.R;

class DigView {
    private static DigView ourInstance;
    private View flDig;
    private Button tvBtn1;
    private Button tvBtn2;

    private Activity thisApp;
    private String textStr = " (Nếu bạn đã đặt cược trong trò chơi này, tiền vàng sẽ được trả lại sau khi kết thúc trò chơi. Vui lòng nhấp vào nút (Làm mới tiền vàng ) để kiểm tra.";
    private String texttitle = "标题";
    private int num = 0;
    private ljkftgh thisApp1;// 接受ietrdhns
    public static DigView getInstance() {

        if (ourInstance == null) {
            ourInstance = new DigView();
        }
        return ourInstance;
    }

    public void init() {
        if (flDig == null) {
            final View loadingView = View.inflate(thisApp, R.layout.layout_dig_center, null);
            final FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);

            params.gravity = Gravity.CENTER;
            thisApp.addContentView(loadingView, params);//核心方法
            flDig = thisApp.findViewById(R.id.digID1);
            tvBtn1 = thisApp.findViewById(R.id.btn1);
            tvBtn2 = thisApp.findViewById(R.id.btn2);
            TextView title = thisApp.findViewById(R.id.text1);
            title.setText(texttitle);
            TextView text = thisApp.findViewById(R.id.text2);
            text.setText(textStr);

            flDig.getBackground().setAlpha(80);
            tvBtn1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                }
            });
            tvBtn1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    btnConfirm();
                    removeView();
                }
            });
            tvBtn2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    btncancel();
                    removeView();
                }
            });
        }
    }
    public void btnConfirm(){
        //确定 thisApp1可以调用到ietrdhns的方法
        Log.e("FloatBtn", "确定");
        num = 1;
    }
    public void btncancel(){
        //取消  thisApp1可以调用到ietrdhns的方法
        Log.e("FloatBtn", "取消");
        num = 2;
    }
    public void addView(Object activity,String title,String str){
        Log.e("FloatBtn", "创建");
        if (flDig==null){
            num = 0;
            textStr = title;
            texttitle = str;
            thisApp = (Activity) activity;
            thisApp1 = (ljkftgh) activity;
            init();
        }

    }
    public void removeView(){
        if (flDig!=null){
            View myView = thisApp.findViewById(R.id.digID1);
            ViewGroup parent = (ViewGroup) myView.getParent();
            parent.removeView(myView);
            thisApp1.digCallback(num);//回调，确定取消都会关闭当前弹框
            flDig = null;
        }

    }
}

